from selenium import webdriver
from selenium.webdriver.common.by import By
from PIL import Image
import ddddocr
import time


bro = webdriver.Edge()
bro.get('http://jw.qdu.edu.cn/homepage/index.do')
bro.save_screenshot('full_page.png')
code_img_ele = bro.find_element(By.ID,'jcaptcha')
location = code_img_ele.location
size = code_img_ele.size
rangle = (
    1.5*int(location['x']),1.5*int(location['y']),1.5*int(location['x']+size['width']),1.5*int(location['y']+size['height']))
i = Image.open('./full_page.png')
name = './coding_result.png'
frame = i.crop(rangle)
frame.save(name)
ocr = ddddocr.DdddOcr()
with open('coding_result.png','rb') as fp:
    img_data = fp.read()
    pass
res = ocr.classification(img_data)
account = bro.find_element(By.XPATH,'//*[@id="login"]/tbody/tr[4]/td/input')
account.send_keys('2021200218')
password = bro.find_element(By.XPATH,'//*[@id="login"]/tbody/tr[6]/td/input')
password.send_keys('11.100.11.10.1')
security_code = bro.find_element(By.XPATH,'//*[@id="login"]/tbody/tr[8]/td/input')
security_code.send_keys(res)
log_in = bro.find_element(By.CLASS_NAME,'button')
log_in.click()
time.sleep(10)
bro.quit()
